import { Component } from '@angular/core';
import {FormsModule} from "@angular/forms";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {NzInputDirective} from "ng-zorro-antd/input";
import {NzSpaceComponent, NzSpaceItemDirective} from "ng-zorro-antd/space";
import {NzTooltipDirective} from "ng-zorro-antd/tooltip";
import {RedisService} from '../services/redis.service';
import {NzMessageService} from 'ng-zorro-antd/message';
import {MqService} from '../services/mq.service';

@Component({
  selector: 'app-rabbitmq',
  standalone: true,
  imports: [
    FormsModule,
    NzButtonComponent,
    NzInputDirective,
    NzSpaceComponent,
    NzTooltipDirective,
    NzSpaceItemDirective
  ],
  templateUrl: './rabbitmq.component.html',
  styleUrl: './rabbitmq.component.css'
})
export class RabbitmqComponent {

  constructor(private mqService: MqService,
              private message: NzMessageService) {}

  directLoading = false;
  directMessage = "测试";
  directSend(){
    this.directLoading = true;
    this.mqService.directSendMessage(this.directMessage).subscribe(res => {
      this.directLoading = false;
        this.message.success("发送消息：" + this.directMessage + "成功！")
    })
  }

  fauntLoading = false;
  fauntMessage="测试"
  fauntSend(){
    this.fauntLoading = true;
    this.mqService.fauntSendMessage(this.fauntMessage).subscribe(res => {
      this.fauntLoading = false;
      this.message.success("发送消息：" + this.fauntMessage + "成功！")
    })
  }

  username="";
  password="";
  serialLoading = false;
  serialSend(){
    this.serialLoading = true;
    this.mqService.serialSendMessage({"username":this.username,"password":this.password}).subscribe(res => {
      this.serialLoading = false;
      this.message.success("发送消息：成功！")
    })
  }

  confirmMsg = "发布确认-交换机";
  confirmLoading = false;
  confirmSend(){
    this.confirmLoading = true;
    this.mqService.confirmSend(this.confirmMsg).subscribe(res => {
      this.confirmLoading = false;
      this.message.success("已发布消息，从 user-service 控制台查看消费情况！")
    })
  }

  returnMsg = "发布确认-队列";
  returnLoading = false;
  returnSend(){
    this.returnLoading = true;
    this.mqService.returnSend(this.returnMsg).subscribe(res => {
      this.returnLoading = false;
      this.message.success("已发布消息，从 user-service 控制台查看消费情况！")
    })
  }

  retryMsg = "重试机制";
  retryLoading = false;
  retrySend(){
    this.retryLoading = true;
    this.mqService.retrySend(this.retryMsg).subscribe(res => {
      this.retryLoading = false;
      this.message.success("已发布消息，从 user-service 控制台查看消费情况！")
    })
  }

  deadMsg = "我是路人甲";
  deadLoading = false;
  deadSend(){
    this.deadLoading = true;
    this.mqService.deadSend(this.deadMsg).subscribe(res => {
      this.deadLoading = false;
      this.message.success("已发布消息，从 user-service 控制台查看消费情况！")
    })
  }
}
